#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QtMultimedia/QCamera>
#include <QImageCapture>
#include "sendimg.h"
#include "mytcpsocket.h"
#include <QListWidget>
#include "sendtext.h"
#include <QMediaCaptureSession>
#include "myvideosurface.h"
#include "partner.h"
#include "recvsolve.h"
#include "audioinput.h"
#include "audiooutput.h"
#include "chatmessage.h"

QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    Ui::Widget *ui;
    static QRect pos;
    quint32 mainip;//主屏幕显示的IP图像
    QCamera *_camera;//摄像头
    QImageCapture *_imagecapture;//截屏
    QMediaCaptureSession *_captureSession; //媒体捕捉会话
    MyVideoSurface *_myvideosurface;

    bool _createmeet;//是否创建会议
    bool _joinmeet;//加入会议
    bool _openCamera;//是否开启摄像头

    SendImg *_sendImg;
    QThread *_imgThread;

    RecvSolve *_recvThread;
    SendText * _sendText;
    QThread *_textThread;

    MyTcpSocket *_mytcpSocket;
    void paintEvent(QPaintEvent *event);

    QMap<quint32, Partner*> partner;//用于记录房间用户
    Partner* addPartner(quint32);
    void removePartner(quint32 ip);
    void closeImg(quint32); //根据IP重置图像
    void clearPartner(); //退出会议，或者会议结束

    void dealMessageTime(QString curMsgTime); //处理时间
    void dealMessage(ChatMessage *messageW, QListWidgetItem *item, QString text, QString time, QString ip ,ChatMessage::User_Type type); //用户发送文本

    //音频
    AudioInput* _ainput;
    QThread* _ainputThread;
    AudioOutput* _aoutput;

    QStringList iplist;

private slots:
    void textSend();
    void cameraError(QCamera::Error, const QString &);
    void cameraImageCapture(QVideoFrame frame);
    void datasolve(MESG *);
    void recvip(quint32);
    void audioError(QString);
    void speaks(QString);

    void on_createmeetBtn_clicked();

    void on_exitmeetBtn_clicked();

    void on_openVideo_clicked();

    void on_openAudio_clicked();

    void on_connServer_clicked();

    void on_joinmeetBtn_clicked();

    void on_horizontalSliderAudio_valueChanged(int value);

    void on_sendmsg_clicked();

signals:
    void PushText(MSG_TYPE, QString = "");
    void pushImg(QImage);
    void stopAudio();
    void startAudio();
    void volumnChange(int);
};
#endif // WIDGET_H
